<!--
  Created by IntelliJ IDEA.
  User: Dai
  Date: 2018/4/4
  Time: 13:41
  To change this template use File | Settings | File Templates.
-->
<!DOCTYPE html>
<html lang="en" layout:decorate="~{default/just_css_and_js}" xmlns:layout="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <link href="/css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
    <style>
        /*这个页面上的表格的样式*/
        .th-inner {
            height: 20px;
            line-height: 20px;
            font-size: 13px;
            padding: 0 !important;
            /* background-image: none; */
            background-color: white;
            border: 0 !important;
        }

        table {
            border: 0 !important;
        }

        tr {
            border: 0 !important;
        }

        /*实时监控 电池包监控 字太多放不下*/
        #package_monitor label {
            padding-right: 0;
            margin-top: 4px;
        }

        #package_monitor span {
            padding-right: 0;
            margin-top: 4px;
        }

        /*实时监控 模组监控 行转列只能用div做了*/
        #model_monitor .div-left div {
            text-align: center;
            padding: 5px 15px;
        }

        #model_monitor .div-left div:first-child {
            background-color: #c2c2c2;
        }

        #model_monitor .div-left {
            float: left;
        }

        #model_monitor .div-left:first-child div {
            padding: 5px 40px;
        }
    </style>
    <script src="/js/echarts.min.js"></script>
    <!-- datepicker 时间选择器 -->
    <script src="/js/bootstrap-datetimepicker.min.js"></script>
    <script src="/js/bootstrap-datetimepicker.zh-CN.js"></script>
    <script>
        /**
         * 限制开始时间和结束时间不能互相超过
         */
        $(function () {
            $("#start_time_select").datetimepicker({
                bootcssVer: 3,   //设置读取bootstrap3，否则默认读取bootstrap2，左右箭头会不见
                startView: 2,
                format: "yyyy-mm-dd",
                minView: "month",
                todayBtn: "linked",
                todayHighlight: true,
                language: "zh-CN",
                showMeridian: true,
                autoclose: true,
                endDate: new Date()
            }).on('changeDate', function (ev) {
                var starttime = $("#start_time_select").val();
                $("#end_time_select").datetimepicker('setStartDate', starttime);
                change_data_type_of_date();
            });
            $("#end_time_select").datetimepicker({
                bootcssVer: 3,   //设置读取bootstrap3，否则默认读取bootstrap2，左右箭头会不见
                startView: 2,
                minView: "month",
                format: "yyyy-mm-dd",
                todayBtn: "linked",
                todayHighlight: true,
                language: "zh-CN",
                autoclose: true,
                showMeridian: true,
                endDate: new Date()
            }).on('changeDate', function (ev) {
                var endtime = $("#end_time_select").val();
                $("#start_time_select").datetimepicker('setEndDate', endtime);
                change_data_type_of_date();
            });
        });

        /**
         * 根据自定义的天数决定是否显示小时
         */
        function change_data_type_of_date() {
            var starttime = $("#start_time_select").val();
            var endtime = $("#end_time_select").val();
            $("#data_freque").empty();
            var str = "";
            var cha = GetDateDiff(starttime, endtime);
            console.log(cha);
            if (cha > 8) {
                str = '<button type="button" class="btn btn-choose-red active">日</button>';
            } else {
                str = '<button type="button" class="btn btn-choose-red active">日</button><button type="button" class="btn btn-choose-red">小时</button>';
            }
            $("#data_freque").prepend(str);
            change_data_type($(this));
            $('#data_freque button').click(function (e) {
                change_data_type($(this));
            });
        }

        /**
         * 计算两个日期之间的相距天数
         */
        function GetDateDiff(starttime, endtime) {
            var startTime = new Date(Date.parse(starttime.replace(/-/g, "/"))).getTime();
            var endTime = new Date(Date.parse(endtime.replace(/-/g, "/"))).getTime();
            var dates = Math.abs((startTime - endTime)) / (1000 * 60 * 60 * 24);
            return dates;
        }
    </script>
    <!--页面上的一些js-->
    <script>
        /**
         * 历史查询中的button
         */
        var str_1 =
            '<button type="button" class="btn btn-choose-red active">replace_this</button>';
        var str_other =
            '<button type="button" class="btn btn-choose-red">replace_this</button>';

        /**
         * 图表
         */
        $(function () {
            /**
             * 历史数据中的图表
             */
            echarts.init(document.getElementById('search_history')).setOption({
                title: {                // 标题
                    left: 'center',
                    top: '3%',
                    text: '大拇指商业广场 <2017-11-14~2017-11-14> 充电量'
                },
                grid: {                 // 设置边距
                    left: '0%',
                    right: '3%',
                    bottom: '10%',
                    containLabel: true  // 是否包含显示的刻度
                },
                tooltip: {              // 提示框组件
                    trigger: 'axis'     // 触发类型 axis坐标轴触发
                },
                legend: {               // 图例
                    data: ['A相电流', 'B相电流', 'C相电流'],
                    x: 'center',        //中间
                    y: 'bottom'         //下方
                },
                toolbox: {              // 工具栏
                    show: true,
                    top: '3%',
                    feature: {
                        dataView: {readOnly: false},        //数据视图
                        magicType: {type: ['line', 'bar']}, //变换类型
                        restore: {},                        //刷新
                        saveAsImage: {}                     //保存图片
                    }
                },
                xAxis: {                // x轴
                    type: 'category',
                    boundaryGap: false,  //坐标轴两边留白，如果是false就是0点在y轴上
                    data: ['09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00']
                },
                yAxis: [
                    {
                        name: '单位(A)',
                        type: 'value',
                        boundaryGap: true,
                        // min: 0,
                        max: function (value) {
                            return value.max + 100;
                        }
                    }
                ],
                series: [
                    {
                        name: 'A相电流',
                        type: 'line',
                        data: [200, 220, 223.5, 300, 395.6, 654.2, 824.3, 725.4, 542.8]
                    },
                    {
                        name: 'B相电流',
                        type: 'line',
                        data: [212.3, 234, 263.5, 350.8, 365.6, 674.2, 854.3, 715.4, 562.8]
                    },
                    {
                        name: 'C相电流',
                        type: 'line',
                        data: [232.3, 222, 243.5, 330.8, 368.6, 634.2, 894.3, 765.4, 512.8]
                    }
                ]
            });
        });

        /**
         * 初始化页面
         */
        $(function () {
            /**
             * 隐藏时间选择
             */
            $("#time_select").hide();
            /**
             * 按钮点击事件
             */
            button_click();
        });

        /**
         * 按钮点击事件
         */
        function button_click() {
            /**
             * 测点类型
             */
            $('#test_type button').click(function (e) {
                change_test_name($(this))
            });
            /**
             * 测点名称
             */
            $('#test_name button').click(function (e) {
                $(this).addClass('active').siblings().removeClass('active');
            });
            /**
             * 时间范围
             */
            $('#time_ranges button').click(function (e) {
                change_data_freque($(this));
            });
            /**
             * 显示密度
             */
            $('#data_freque button').click(function (e) {
                change_data_type($(this));
            });
            /**
             * 显示类别
             */
            $('#data_type button').click(function (e) {
                $(this).addClass('active').siblings().removeClass('active');
            });
        }

        /**
         * 当测点类型改变时，改变对应的测点名称
         */
        function change_test_name(button) {
            $(button).addClass('active').siblings().removeClass('active');
            var text = $(button).text();
            $("#test_name").empty();
            var str = "";
            switch (text) {
                case "能量":
                    str = str_1.replace("replace_this", "可储存电量") + str_other.replace("replace_this", "总电量") + str_other.replace("replace_this", "各次放出的能量");
                    break;
                case "电压":
                    str = str_1.replace("replace_this", "总电压") + str_other.replace("replace_this", "单体电压极值和极差(单选)");
                    break;
                case "电流":
                    str = str_1.replace("replace_this", "电流");
                    break;
                case "温度":
                    str = str_1.replace("replace_this", "温度") + str_other.replace("replace_this", "单体温度极值和极差(多选)");
                    break;
                case "SOC":
                    str = str_1.replace("replace_this", "SOC");
                    break;
                case "循环次数":
                    str = str_1.replace("replace_this", "循环次数");
                    break;
            }
            $("#test_name").prepend(str);
            $('#test_name button').click(function (e) {
                $(this).addClass('active').siblings().removeClass('active');
            });
        }

        /**
         * 当时间范围变化时，变化显示密度
         */
        function change_data_freque(button) {
            $(button).addClass('active').siblings().removeClass('active');
            var text = $(button).text();
            $("#data_freque").empty();
            var str = "";
            switch (text) {
                case "日":
                    str = str_1.replace("replace_this", "小时") + str_other.replace("replace_this", "15分钟");
                    $("#time_select").hide();
                    break;
                case "周":
                    str = str_1.replace("replace_this", "日") + str_other.replace("replace_this", "小时");
                    $("#time_select").hide();
                    break;
                case "月":
                    str = str_1.replace("replace_this", "日");
                    $("#time_select").hide();
                    break;
                case "年":
                    str = str_1.replace("replace_this", "月");
                    $("#time_select").hide();
                    break;
                case "自定义":
                    str = str_1.replace("replace_this", "日") + str_other.replace("replace_this", "小时");
                    $("#time_select").show();
                    break;
            }
            $("#data_freque").prepend(str);
            change_data_type($(this));
            $('#data_freque button').click(function (e) {
                change_data_type($(this));
            });
        }

        /**
         * 当显示密度变化时，变化显示类别
         */
        function change_data_type(button) {
            $(button).addClass('active').siblings().removeClass('active');
            var text = $(button).text();
            if (text == '15分钟') {
                $("#data_type").empty();
                $("#data_type").prepend(str_1.replace("replace_this", "瞬态值"));
            } else {
                if ($("#data_type").children().size() != 3) {
                    var str = str_1.replace("replace_this", "平均值") + str_other.replace("replace_this", "最大值") + str_other.replace("replace_this", "最小值");
                    $("#data_type").empty();
                    $("#data_type").prepend(str);
                }
            }
            /**
             * 显示类别
             */
            $('#data_type button').click(function (e) {
                $(this).addClass('active').siblings().removeClass('active');
            });
        }
    </script>
</head>
<body>
<div layout:fragment="content">
    <div class="main-content-inner">
        <input type="hidden" id="id" th:value="${id}">
        <!--面包屑导航栏-->
        <ul class="breadcrumb">
            <li>
                <a href="#">系统监控</a>
            </li>
            <li class="active" th:text="${grandparentParentName}"></li>
            <li class="active" th:text="${grandparentName}"></li>
            <li class="active" th:text="${parentName}"></li>
            <li class="active" th:text="${name}"></li>
        </ul>
        <!-- 内容显示 -->
        <div>
            <!--实时监控-->
            <div>
                <h3 class="col-sm-12" style="border-bottom: 2px solid grey; padding: 5px; margin-top: 0;">实时监控</h3>
                <div class="col-sm-4">
                    <label>电压(V)</label>
                    <span></span>
                </div>
                <div class="col-sm-4">
                    <label>电流(A)</label>
                    <span></span>
                </div>
                <div class="col-sm-4">
                    <label>温度(℃)</label>
                    <span></span>
                </div>
            </div>
            <!--诊断分析-->
            <form>
                <h3 class="col-sm-12" style="border-bottom: 2px solid grey; padding: 5px">诊断分析</h3>
                <!--单体SOC-->
                <fieldset class="col-sm-3" style="margin: 15px; width: 30%">
                    <legend>单体SOC</legend>
                    <div style="font-weight: bolder">
                        <span class="col-sm-3"><span>66</span>%</span>
                        <i class="glyphicon glyphicon-arrow-up" style="color: red; float: left"></i>
                        <span class="col-sm-2"><span>66</span>%</span>
                    </div>
                    <!--刷新按钮-->
                    <button type="button" style="background: white; color: black; border: 0;float: right; ">
                        <i class="glyphicon glyphicon-refresh" style="color: black"></i>
                    </button>
                </fieldset>
                <!--单体容量-->
                <fieldset class="col-sm-3" style="margin: 15px; width: 30%">
                    <legend>单体容量</legend>
                    <div style="font-weight: bolder">
                        <span class="col-sm-3"><span>66</span>Ah</span>
                        <i class="glyphicon glyphicon-arrow-up" style="color: red; float: left"></i>
                        <span class="col-sm-2"><span>66</span>Ah</span>
                    </div>
                    <!--刷新按钮-->
                    <button type="button" style="background: white; color: black; border: 0;float: right; ">
                        <i class="glyphicon glyphicon-refresh" style="color: black"></i>
                    </button>
                </fieldset>
                <!--直流内阻DCIR-->
                <fieldset class="col-sm-3" style="margin: 15px; width: 30%">
                    <legend>直流内阻DCIR</legend>
                    <div style="font-weight: bolder">
                        <span class="col-sm-3"><span>66</span>mΩ</span>
                        <i class="glyphicon glyphicon-arrow-up" style="color: red; float: left"></i>
                        <span class="col-sm-2"><span>66</span>mΩ</span>
                    </div>
                    <!--刷新按钮-->
                    <button type="button" style="background: white; color: black; border: 0;float: right; ">
                        <i class="glyphicon glyphicon-refresh" style="color: black"></i>
                    </button>
                </fieldset>
            </form>
            <!--历史曲线-->
            <div id="default-step-1">
                <h3 class="col-sm-12" style="border-bottom: 2px solid grey; padding: 5px">历史曲线</h3>
                <div class="col-sm-12">
                    <form style="margin-top: 10px" class="col-sm-12">
                        <!--测点类别-->
                        <div>
                            <label style="margin-right: 15px">测点类别</label>
                            <div id="test_type" class="btn-group btn-group-sm">
                                <button type="button" class="btn btn-choose-red active">电压</button>
                                <button type="button" class="btn btn-choose-red">电流</button>
                                <button type="button" class="btn btn-choose-red">温度</button>
                            </div>
                        </div>
                        <!--测点名称-->
                        <div>
                            <label style="margin-right: 15px">测点名称</label>
                            <div id="test_name" class="btn-group btn-group-sm">
                                <button type="button" class="btn btn-choose-red active">总电压</button>
                                <button type="button" class="btn btn-choose-red">单体电压极值和极差(单选)</button>
                            </div>
                        </div>
                        <!--时间范围-->
                        <div>
                            <label style="margin-right: 15px">时间范围</label>
                            <div id="time_ranges" class="btn-group btn-group-sm">
                                <button type="button" class="btn btn-choose-red active">日</button>
                                <button type="button" class="btn btn-choose-red">周</button>
                                <button type="button" class="btn btn-choose-red">月</button>
                                <button type="button" class="btn btn-choose-red">年</button>
                                <button type="button" class="btn btn-choose-red">自定义</button>
                                <div style="display: inline-block" id="time_select">
                                    <input class="form_date"
                                           style="height: 30px; background-color: white !important; border-radius: 5px !important"
                                           type="text" placeholder="开始时间"
                                           id="start_time_select" data-link-field="start_time"
                                           data-link-format="yyyy-mm-dd"
                                           readonly>
                                    <span>至</span>
                                    <input class="form_date"
                                           style="height: 30px; background-color: white !important; border-radius: 5px !important"
                                           type="text" placeholder="结束时间"
                                           id="end_time_select" data-link-field="end_time" data-link-format="yyyy-mm-dd"
                                           readonly>
                                    <input type="hidden" id="start_time" name="start_time">
                                    <input type="hidden" id="end_time" name="end_time">
                                </div>
                            </div>
                        </div>
                        <!--显示密度-->
                        <div>
                            <label style="margin-right: 15px">显示密度</label>
                            <div id="data_freque" class="btn-group btn-group-sm">
                                <button type="button" class="btn btn-choose-red active">小时</button>
                                <button type="button" class="btn btn-choose-red">15分钟</button>
                            </div>
                        </div>
                        <!--显示类别-->
                        <div>
                            <label style="margin-right: 15px">显示类别</label>
                            <div id="data_type" class="btn-group btn-group-sm">
                                <button type="button" class="btn btn-choose-red active">平均值</button>
                                <button type="button" class="btn btn-choose-red">最小值</button>
                                <button type="button" class="btn btn-choose-red">最大值</button>
                            </div>
                        </div>
                    </form>
                    <!--图-->
                    <div id="search_history" class="col-sm-12"
                         style="height: 400px; margin-top: 10px; border-top: 1px solid #C5D0DC;"></div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>